home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************************
- Snippet: MeterTest.c
-
- Description: This snippet demonstrates record metering through the use of SPBGetDeviceInfo()
- and SPBSetDeviceInfo() using the siLevelMeterOnOff selector. The code calls
- SPBSetDeviceInfo() to initially set metering to off, then does a quick sampling of
- sound input using SPBGetDeviceInfo(). Metering is then turned on and sampling is
- repeated. This is an SIOW application and could be done more elegantly using a
- graphical representation for sound input levels. But you get the idea. . .
-
- Programmer: Kevin Mellander
- Organization: Apple Computer, Inc.
- Department Developer Technical Support, DTS
- Language/Envir. MPW Version 3.3.1
- Date Created 7/5/94
-
- *****************************************************************************************/
- #include <Sound.h>
- #include <SoundInput.h>
- #include <ToolUtils.h>
- #include <Types.h>
- #include <stdio.h>
-
- struct soundLevelData{
- short meterState;
- short meterSetting;
- } getSoundLevelInfo;
-
- void main()
- {
- Str255 deviceString;
- OSErr soundErr = 0;
- long mySIRefNum;
- short sampletime = 0;
- short setSoundMeterState = 1;
-
- getSoundLevelInfo.meterState = 0;
- getSoundLevelInfo.meterSetting = 0;
-
- deviceString[0] = 0;
-
- //Open the sound input device
- soundErr = SPBOpenDevice(deviceString,siWritePermission,&mySIRefNum);
- if (soundErr != noErr)
- DebugStr("\p Failure at call to SPBOpenDevice");
-
- //Set the initial state of the sound input meter to zero just to be sure we start in an "off" state--after all this *is* a test
- soundErr = SPBSetDeviceInfo(mySIRefNum,siLevelMeterOnOff,(Ptr) &getSoundLevelInfo.meterState);
- if (soundErr != noErr)
- DebugStr("\p Failure at call to SPBSetDeviceInfo set to 0");
-
- //Monitor sound input and make sure everything is really zeroed
- for (sampletime = 0; sampletime<=100; ++sampletime)
- {
- soundErr = SPBGetDeviceInfo(mySIRefNum,siLevelMeterOnOff, (Ptr) &getSoundLevelInfo);
- if (soundErr != noErr)
- DebugStr("\p Failure at call to SPBGetDeviceInfo");
- else
- printf("The GetDeviceInfo meter state is %d and the meter setting is %d\n",getSoundLevelInfo.meterState,getSoundLevelInfo.meterSetting);
- }
-
- //Turn the sound input meter on
- soundErr = SPBSetDeviceInfo(mySIRefNum,siLevelMeterOnOff,(Ptr) &getSoundLevelInfo.meterState);
- if (soundErr != noErr)
- DebugStr("\p Failure at call to SPBSetDeviceInfo set to 1");
- else
- printf("\nThe call to SPBGetDeviceInfo was successful;\nThe SetDeviceInfo meter state was set to %i\n\n",setSoundMeterState);
-
-
- //Monitor sound input again with meters on
- for (sampletime = 0; sampletime<=100; ++sampletime)
- {
- soundErr = SPBGetDeviceInfo(mySIRefNum,siLevelMeterOnOff, (Ptr) &getSoundLevelInfo);
- if (soundErr != noErr)
- DebugStr("\p Failure at call to SPBGetDeviceInfo");
- else
- printf("The GetDeviceInfo meter state is %d and the meter setting is %d\n",getSoundLevelInfo.meterState,getSoundLevelInfo.meterSetting);
-
- }
-
- //We're done so close the device
- soundErr = SPBCloseDevice(mySIRefNum);
- if (soundErr != noErr)
- DebugStr("\p Failure at call to SPBCloseDevice");
- }